package com.haixiaoke.saas.repository.service;

import com.haixiaoke.saas.repository.dto.HouseAndAllocationDTO;
import com.haixiaoke.saas.repository.dto.OrderCheckOutDTO;
import com.haixiaoke.saas.repository.dto.OrderDTO;
import com.haixiaoke.saas.repository.dto.OrderWxRefundDTO;
import com.haixiaoke.saas.repository.pojo.CalendarPrice;
import com.haixiaoke.saas.repository.pojo.HousingAllocation;
import com.haixiaoke.saas.repository.pojo.Order;
import com.haixiaoke.saas.repository.pojo.PayType;
import com.haixiaoke.saas.repository.vo.HouseConditionVO;
import com.haixiaoke.saas.repository.vo.OrderAmountVO;
import com.haixiaoke.saas.repository.vo.OrderInfoVO;
import com.haixiaoke.saas.repository.vo.OrderVO;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单Service接口
 *
 * @author haixiaoke
 * @date 2023-04-12
 */
public interface IOrderService {
    /**
     * 查询订单
     *
     * @param orderId 订单主键
     * @return 订单
     */
    public OrderVO selectOrderDetailsByOrderId(String orderId);

    /**
     * 预订人id查询订单
     *
     * @param reservationId 预订人
     * @return 订单
     */
    public List<Order> selectOrderByReservationId(String reservationId);

    /**
     * 查询订单列表
     *
     * @param order 订单
     * @return 订单集合
     */
    List<Order> selectOrderList(Order order);

    /**
     * 新增订单
     *
     * @param order 订单
     * @return 结果
     */
    public int insertOrder(Order order);

    /**
     * 修改订单
     *
     * @param order 订单
     * @return 结果
     */
    int updateOrder(Order order);

    /**
     * 批量删除订单
     *
     * @param orderIds 需要删除的订单主键集合
     * @return 结果
     */
    int deleteOrderByOrderIds(Long[] orderIds);

    /**
     * 删除订单信息
     *
     * @param orderId 订单主键
     * @return 结果
     */
    int deleteOrderByOrderId(Long orderId);

    /**
     * 查询订单所选的房屋及房屋配置信息及操作人信息
     *
     * @param houseId 房屋id
     * @return
     */
    HouseAndAllocationDTO selectHouseAndAllocation(String houseId);

    /**
     * 根据房屋配置的金额，计算金额，并统计金额
     *
     * @param calendarPriceList 日历价格集合
     * @param payType           押付方式
     * @param housingAllocation 房屋配置
     * @param orderDTO          订单入住时间、退房时间
     * @param cashPledgeBoolean 是否计算租金
     * @return
     */
    OrderAmountVO computedAmount(List<CalendarPrice> calendarPriceList, PayType payType, HousingAllocation housingAllocation, OrderDTO orderDTO, Boolean cashPledgeBoolean);

    /**
     * 续租统计金额
     *
     * @param calendarPriceList 日历价格集合
     * @param payType           押付方式
     * @param housingAllocation 房屋配置
     * @param orderDTO          订单下单参数
     * @return
     */
//    OrderAmountVO reletComputedAmount(List<CalendarPrice> calendarPriceList, PayType payType, HousingAllocation housingAllocation, OrderDTO orderDTO);

    /**
     * 校验订单的状态--false为订单校验不通过
     *
     * @param cacheKey 订单id
     * @return
     */
    Boolean checkOrderState(String cacheKey);

    /**
     * 创建订单 true为创建成功
     *
     * @param orderDTO
     */
    Order createOrder(OrderDTO orderDTO, HouseAndAllocationDTO houseAndAllocationDTO);

    /**
     * 修改订单的状态
     *
     * @param order
     * @return
     */
    int updateOrderState(Order order);

    /**
     * 小程序微信支付
     *
     * @param orderDTO
     * @param houseAndAllocationDTO
     * @param order
     * @return
     */
    Map<String, Object> orderWxPay(OrderDTO orderDTO, HouseAndAllocationDTO houseAndAllocationDTO, Order order);

    Map<String, Object> reletOrderWxPay(OrderDTO orderDTO, Order order);

    /**
     * 从缓存获取消息，并且格式化
     *
     * @param redisKey
     * @return
     */
    HouseAndAllocationDTO parseHouseMsg(String redisKey);

    /**
     * 根据订单id查订单基本信息
     *
     * @param orderId 订单id
     * @return
     */
    Order selectOrderById(String orderId);

    List<Order> selectOrderListValid(Order order);

    Map<String, Object> orderRePay(Order order, OrderDTO orderDTO);

    List<Map<String, Object>> getStateList();

    /**
     * 订单退款
     *
     * @param orderWxRefundDTO
     * @return
     */
    Map<String, String> orderRefund(OrderWxRefundDTO orderWxRefundDTO);

    Boolean checkTimeValid(Date checkInTime, Date checkOutTime, Date rentableStartTime, Date rentableEndTime);

    /**
     * 查询订单状态
     *
     * @param orderId
     * @return
     */
    Order selectOrderStateById(String orderId);

    OrderAmountVO reletOrder(OrderDTO orderDTO, Order order, HousingAllocation housingAllocation);

    List<Order> selectOrderByOrderState(Integer orderState);

    int updateReLetOrder(Order order);

    void deleteUnRelet(String orderId);

    OrderCheckOutDTO checkOutInfo(String orderId);

    void orderRebates(Order order, OrderWxRefundDTO refund, OrderCheckOutDTO orderCheckOutDTO);

    Order selectOrderByHouseId(String houseId);

    Order rebatesInfo(String orderId);

    /**
     * 根据id集合查询order集合
     * @param orderIds 订单id集合
     * @return
     */
    List<Order> selectOrderByIds(String[] orderIds);

    OrderInfoVO orderInfo(String orderId);

    List<Order> selectOrderListByHouse(Order order);

    /**
     * 房态查询指定范围的订单
     * @param order
     * @return
     */
    List<HouseConditionVO> selectOrderCondition(Order order);
}
